package com.janko.springbootbase.jvm.oom;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;

/**
 * @Author nyk
 * @Date 2021/5/8 14:53
 * @Version 1.0
 * @Desc OOM内存溢出的测试案例
 */
@RestController
public class MyMainController {

    /**
     * 制造一个OOM场景
     * JVM设置：-Xms8m -Xmx8m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath="E:\heapdump.hprof"
     *
     */

    public static void main(String[] args) {
//        ArrayList<Object> list = new ArrayList<>(100000);
//        while (true) {
//            list.add(new Object());
//        }
    }

    @GetMapping("/oom")
    public void OOM(){
        System.out.println("开始测试OOM");
        ArrayList<Object> list = new ArrayList<>(100000);
        while (true) {
            list.add(new Object());
        }
    }
}
